home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 1998
- // Author: DRB
- //
- global proc makeBrushSpring(
- float $defStiff, float $defDamp, float $defTravel, int $startFrame )
- {
- int $i;
- string $brushes[];
-
- $brushes = getSelectedBrushes();
- int $numBrushes = size( $brushes );
-
- if( $numBrushes == 0 )
- {
- warning( "No brushes or strokes selected!" );
- return;
- }
-
- for( $i = 0; $i < $numBrushes; $i++ )
- {
- string $brush = $brushes[$i];
- string $stroke[] = `listConnections ( $brush + ".outBrush")`;
- if( size( $stroke ) > 0 )
- {
- string $curve[] = `listConnections ( $stroke[0] + ".pathCurve[0].curve")`;
- if( size( $curve ) > 0 )
- {
- if( `nodeType $curve[0]` == "curveFromSurfaceCoS")
- {
- $curve = `listConnections ( $curve[0] + ".curveOnSurface")`;
- if( size( $curve ) <= 0 )
- {
- continue;
- }
- }
-
- // For multiple invokations we should probably try to reuse
- // existing pointOnCurve nodes, instead of letting them pile
- // up.
- string $poc = `pointOnCurve -ch on -parameter 0.5 $curve[0]`;
-
- if ( !objExists( $curve[0] + ".lastWX" ) )
- {
- addAttr -sn lwx -ln lastWX -dv 0 $curve[0];
- }
- else
- {
- string $expNode[] = `listConnections ($curve[0] + ".lastWX")`;
- if( size( $expNode ) > 0 )
- {
- // This should be another spring expression Node
- // We delete it to make way for the new one
- delete $expNode[0];
- }
- }
- if ( !objExists( $curve[0] + ".lastWY" ) )
- {
- addAttr -sn lwy -ln lastWY -dv 0 $curve[0];
- }
- if ( !objExists( $curve[0] + ".lastWZ" ) )
- {
- addAttr -sn lwz -ln lastWZ -dv 0 $curve[0];
- }
- if ( !objExists( $curve[0] + ".lastVX" ) )
- {
- addAttr -sn lvx -ln lastVX -dv 0 $curve[0];
- }
- if ( !objExists( $curve[0] + ".lastVY" ) )
- {
- addAttr -sn lvy -ln lastVY -dv 0 $curve[0];
- }
- if ( !objExists( $curve[0] + ".lastVZ" ) )
- {
- addAttr -sn lvz -ln lastVZ -dv 0 $curve[0];
- }
- if ( !objExists( $brush + ".springStiffness" ) )
- {
- addAttr -sn sst -ln springStiffness -dv $defStiff -min 0 -max 1 $brush;
- }
- else
- {
- setAttr ($brush + ".springStiffness") $defStiff;
- }
- if ( !objExists( $brush + ".springDamp" ) )
- {
- addAttr -sn sdp -ln springDamp -dv $defDamp -min 0 -max 1 $brush;
- }
- else
- {
- setAttr ($brush + ".springDamp") $defDamp;
- }
- if ( !objExists( $brush + ".springTravel" ) )
- {
- addAttr -sn spt -ln springTravel -dv $defTravel -min 0 -max 100 $brush;
- }
- else
- {
- setAttr ($brush + ".springTravel") $defTravel;
- }
- string $expStr = "";
-
- $expStr = $expStr + (
- "float $px = " + $poc + ".positionX;\n"
- + "float $py = " + $poc + ".positionY;\n"
- + "float $pz = " + $poc + ".positionZ;\n"
- + "float $wx = " + $curve[0] + ".lastWX;\n"
- + "float $wy = " + $curve[0] + ".lastWY;\n"
- + "float $wz = " + $curve[0] + ".lastWZ;\n"
- + "float $vx = " + $curve[0] + ".lastVX;\n"
- + "float $vy = " + $curve[0] + ".lastVY;\n"
- + "float $vz = " + $curve[0] + ".lastVZ;\n"
- + "float $stiff = " + $brush + ".springStiffness;\n"
- + "float $istiff = 1-$stiff;\n"
- + "float $damp = 1 - " + $brush + ".springDamp;\n"
- + "float $travel = " + $brush + ".springTravel;\n"
- + "float $fx = 0; float $fy = 0; float $fz = 0;\n"
- + "if( frame > " + ($startFrame + 1) + " ){\n"
- + " $fx = " + $brush + ".uniformForceX * $istiff + $stiff * ($wx - $px) * $travel + $vx;\n"
- + " $fy = " + $brush + ".uniformForceY * $istiff + $stiff * ($wy - $py) * $travel + $vy;\n"
- + " $fz = " + $brush + ".uniformForceZ * $istiff + $stiff * ($wz - $pz) * $travel + $vz;\n"
- + " " + $curve[0] +".lastVX = $vx * $damp -$fx * $stiff;\n"
- + " " + $curve[0] +".lastVY = $vy * $damp -$fy * $stiff;\n"
- + " " + $curve[0] +".lastVZ = $vz * $damp -$fz * $stiff;\n"
- + "}else{\n"
- + " " + $curve[0] +".lastVX = 0;\n"
- + " " + $curve[0] +".lastVY = 0;\n"
- + " " + $curve[0] +".lastVZ = 0;\n"
- + "}\n"
- + $brush + ".uniformForceX = $fx;\n"
- + $brush + ".uniformForceY = $fy;\n"
- + $brush + ".uniformForceZ = $fz;\n"
- + $curve[0] +".lastWX = $px;\n"
- + $curve[0] +".lastWY = $py;\n"
- + $curve[0] +".lastWZ = $pz;\n" );
- expression -s $expStr;
- }
- }
- }
-
- }
-
-